#include <iostream>
#include <vector>
#include <math.h>
using namespace std;
class Solution
{
public:
    int sum = 0;
    void solve(vector<int> &nums, int n, int i, int currXor)
    {
        if (i == n)
        {
            // reached null of one subset
            sum += currXor;
            return;
        }
        // including XOR of nums[i]
        solve(nums, n, i + 1, currXor ^ nums[i]);
        // excluding XOR of nums[i]
        solve(nums, n, i + 1, currXor);
    }

    int subsetXORSum(vector<int> nums)
    {

        int n = nums.size();
        int currXor = 0;
        solve(nums, n, 0, currXor);
        return sum;
    }

    int ans = 0;
    void backtrack(vector<int> &nums, int cnt, int sum, int start)
    {
        // vector<int>visited(nums.size(),0);

        if (cnt <= nums.size())
            ans += sum;

        for (int i = start; i < nums.size(); i++)
        {
            // if(visited[nums[i]])
            //   continue;
            // visited[nums[i]]=1;
            int old = sum;
            sum = sum ^ nums[i];
            backtrack(nums, cnt + 1, sum, i + 1);
            sum = old;
            // visited[nums[i]]=0;
        }
        return;
    }

    int subsetXORSum_2(vector<int> &nums)
    {
        int sum = 0;
        int cnt = 0;
        // vector<int>visited(nums.size(),0);
        backtrack(nums, cnt, sum, 0);
        return ans;
    }

    int subsetXORSum_3(vector<int> nums)
    {
        int bits = 0;
        for (int i = 0; i < nums.size(); i++)
        {
            bits |= nums[i];
        }
        return bits * pow(2, nums.size() - 1);
    }
};
int main()
{
    /**
     * @brief
     * 5,1,6 - 28
     */
    Solution s;
    cout << s.subsetXORSum_3({5, 1, 6}) << endl;
    return 0;
}
